#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This module provides common error handling exceptions and logging
methods.
"""

import tatolib.strutil as strutil

class DoNothingLogger(object):
    def err(self, msg):
        pass
    def msg(self, msg):
        pass

class StdoutLogger(object):
    def err(self, msg):
        print (strutil.u_("[ERR] {0}").format(msg))
    def out(self, msg):
        print (strutil.u_("[MSG] {0}").format(msg))

# Constants for exceptions. They are not localized so programmers can
# use it to determine the details of an exception.
E_DB_WRONGPATH        = "DatabaseWrongPath"
E_DB_NOTFILE          = "DatabaseIsNotAFile"
E_DB_CORRUPTED        = "DatabaseCorruprted"
E_DB_WRONGVERSION     = "DatabaseWrongVersion"
E_DB_ATTRMISSING      = "DatabaseAttributeMissing"
E_DB_TABLEMISSING     = "DatabaseTableMissing"
E_DB_BADTYPE          = "DatabaseBadType"

E_TA_ATTRMISSING      = "TaskAttributeMissing"
E_TA_BADVALUE         = "TaskBadValue"
E_TA_WRONGTYPE        = "TaskWrongType"
E_TA_SAMENAME         = "TagSameName"
E_TA_SIMILARNAME      = "TagSimilarName"
E_TA_BADNAMEID        = "TagBadNameIDCalculation"

class DatabaseError(ValueError):
    def __init__(self, table, error):
        Exception.__init__(self)
        self.table = table
        self.error = error
        self.__message = strutil.u_("{0}: {1}").format(table, error)
    def __str__(self):
        return self.__message

class TaskObjectError(ValueError):
    def __init__(self, objname, error):
        Exception.__init__(self)
        self.objname = objname
        self.error = error
        self.__message = strutil.u_("{0}: {1}").format(objname, error)
    def __str__(self):
        return self.__message

class InternalError(Exception):
    def __init__(self, message, value):
        Exception.__init__(self)
        self.__message = strutil.u_("Internal error: {0}: {1}").format(\
                                    message, value)
    def __str__(self):
        return self.__message


# vim:tw=78:et:sw=4
